package com.neuedu.service.impl;

import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.neuedu.pojo.AdminTable;
import com.neuedu.pojo.Result;
import com.neuedu.pojo.UserTable;
import com.neuedu.service.UserTableService;
import com.neuedu.mapper.UserTableMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
* @author Administrator
* @description 针对表【user_table(用户信息表)】的数据库操作Service实现
* @createDate 2025-06-17 09:04:08
*/
@Service
public class UserTableServiceImpl extends ServiceImpl<UserTableMapper, UserTable>
    implements UserTableService{
    @Autowired
    private UserTableMapper userTableMapper;

    @Override
    public Result<Void> addUserTable(UserTable userTable) {
        userTable.setIsDelete(0);
        userTable.setRegisterTime(new Date());
        userTable.setUpdateTime(new Date());
        // 添加
        int insert = this.userTableMapper.insert(userTable);
        if (insert > 0){
            return Result.success();
        }
        return Result.fail();
    }

    @Override
    public Result<Void> deleteUserTable(Integer id) {
        LambdaUpdateWrapper<UserTable> wrapper = new LambdaUpdateWrapper<>();
        wrapper.set(UserTable::getIsDelete,1)
                .eq(UserTable::getUserId,id);
        int update = this.userTableMapper.update(wrapper);
        if (update > 0){
            return Result.success();
        }
        return Result.fail();
    }

    @Override
    public Result<Void> updateUserTable(UserTable userTable) {
        userTable.setUpdateTime(new Date());
        // 添加
        int insert = this.userTableMapper.updateById(userTable);
        if (insert > 0){
            return Result.success();
        }
        return Result.fail();
    }
}




